#!/bin/bash
function download() {
    [ ! -f erofs-utils-1.5.tar.gz ] && wget -O erofs-utils-1.5.tar.gz https://git.kernel.org/pub/scm/linux/kernel/git/xiang/erofs-utils.git/snapshot/erofs-utils-1.5.tar.gz
    tar -xzf erofs-utils-1.5.tar.gz
}

function copy() {
    cp -r erofs-utils-1.5/lib erofs-utils-1.5/include erofs-utils-1.5/VERSION erofs-utils-1.5/configure.ac erofs-utils-1.5/Makefile.am erofs-utils-1.5/scripts .
}

function apply_patch() {
    ls patches | while read patch; do
        patch -p0 < patches/"$patch"
    done
}

if [ ! -d erofs-utils-1.5 ]; then
    download
    copy
    apply_patch
fi
